%"best_index" - in 1s/0s shows the postion of a trial, "best_trigger" - again shows the postion but in the range 1 .. n
function [best_index,best_trigger,class_start_pos,class_end_pos] = generate_trials_postitions_using_discrete_channel(m, trial_channel, class_separation_channel)
    
classes = (class_separation_channel >0);
trials = (trial_channel >0);

class_end_positions = find(diff(classes)==1);

trial_positions = find(diff(trials)==1);

trial_positions = trial_positions + 1;

if (m==1)
    result = trial_positions(trial_positions'<class_end_positions(m));
   
    class_start_pos = 1;
    class_end_pos = class_end_positions(m);
   
else
    
    result = trial_positions(trial_positions'>class_end_positions(m-1) & trial_positions'<class_end_positions(m));
    
    class_start_pos = class_end_positions(m-1);
    class_end_pos = class_end_positions(m);
end;
    

best_index = result;
best_trigger = trials(class_start_pos:class_end_pos);





